# encoding: UTF-8
"""

@author = 李林名
@email = lishuai1199@qq.com
@create_time = 2022/11/24 21:27

"""
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep


# #1.使用xpath选择器,使用组合|获取元素,并显示:      北京  纽约
# wd = webdriver.Chrome()
# wd.get('https://cdn2.byhy.net/files/selenium/test1.html')
#
# ##根据id获取元素
# elements=wd.find_elements(By.XPATH,'//div[@id="china"]/p[1] | //div[@id="us"]/span[1]/p[1]')
# for element in elements:
#     print(element.get_attribute('innerHTML'))
# sleep(2)


# #2.使用xpath选择器,使用组合|获取元素,并显示:      北京  纽约
# wd = webdriver.Chrome()
# wd.get('https://cdn2.byhy.net/files/selenium/test1.html')
#
# ##根据id获取元素
# elements=wd.find_elements(By.XPATH,'//div[@id="china"]/p[1] | //div[@id="us"]/span[1]/p[1]')
# for element in elements:
#     print(element.get_attribute('innerHTML'))
# sleep(2)


# #3.使用xpath选择器,使用组合|获取元素,并显示:      北京  纽约
# wd = webdriver.Chrome()
# wd.get('https://cdn2.byhy.net/files/selenium/test1.html')
#
# ##根据id获取元素
# elements=wd.find_elements(By.XPATH,'//div[@id="china"]/p[1] /../../div[last()]/span[1]/p[1]|//div[@id="china"]/p[1]')
# for element in elements:
#     print(element.get_attribute('innerHTML'))
# sleep(2)


# #4.使用xpath选择器,使用后续兄弟follow-subling获取元素,并显示:     芝加哥
# wd = webdriver.Chrome()
# wd.get('https://cdn2.byhy.net/files/selenium/test1.html')
#
# ##根据id获取元素
# elements=wd.find_elements(By.XPATH,'//span/following-sibling::*/p')
# for element in elements:
#     print(element.get_attribute('innerHTML'))
# sleep(2)


# #4.使用xpath选择器,使用后续兄弟preceding-subling获取元素,并显示:     纽约
# wd = webdriver.Chrome()
# wd.get('https://cdn2.byhy.net/files/selenium/test1.html')
#
# ##根据id获取元素
# elements=wd.find_elements(By.XPATH,'//span/p[2]/preceding-sibling::*')
# for element in elements:
#     print(element.get_attribute('innerHTML'))
# sleep(2)